using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmallJob.Model;
using SmallJob.Data;
using SmallJob.Services.Interfaces;
using SmallJob.Data.Interfaces;
using SmallJob.Services.Code;

namespace SmallJob.Services.Implements
{
    public class FollowerService: RepositoryBase<Follower>,IFollowerService
    {
        public FollowerService(IDatabaseFactory DbFactory) : base(DbFactory) { }
        public Boolean IsExist(int followerID, int userID) {
            var follow = (from f in SmallJobDB.Followers
                          where f.FollowerID == followerID && f.UserID == userID 
                          select f).FirstOrDefault();
            return follow != null;
        }
        public Follower GetByID(int followerID, int userID) {
            var follow = (from f in SmallJobDB.Followers
                          where f.FollowerID == followerID && f.UserID == userID
                          select f).FirstOrDefault();
            return follow;
        }
        public int CountFollower(int userID) {
            var follow = from f in SmallJobDB.Followers
                          where f.UserID == userID && !f.IsDeleted
                          select f;
            return follow.Count();
        }
        public List<Follower> GetFollowUser(int userID)
        {
            var follow = from f in SmallJobDB.Followers
                         where f.UserID == userID && !f.IsDeleted
                         select f;
            return follow.ToList();
        }
        public List<Follower> GetUserFollow(int followID)
        {
            var follow = from f in SmallJobDB.Followers
                         where f.FollowerID == followID && !f.IsDeleted
                         select f;
            return follow.ToList();
        }
    }
}
